﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace TranThiQuynhUyen
{
    /// <summary>
    /// Interaction logic for cau2.xaml
    /// </summary>
    public partial class cau2 : Window
    {
        public cau2()
        {
            InitializeComponent();
        }
        
        static SINHVIEN hd = new SINHVIEN();
        static Cau2DAL dal = new Cau2DAL();
        DataRowView datarow;
        bool addnew = true;
        string MSV;
        
        
        public cau2(DataRowView datarow,bool addnew) : this()
        {
            this.datarow=datarow;
            this.addnew = addnew;
            if (addnew == false)
            {
                MSV = datarow["masv"].ToString();
                masv1.Text = MSV;
                ho1.Text = datarow["ho"].ToString(); 
                ten1.Text = datarow["ten"].ToString();
                gt.Text = datarow["gioitinh"].ToString();
                ngsinh.Text = datarow["ngaysinh"].ToString();
                makhoa1.Text = datarow["makhoa"].ToString();
            }
        }
        public cau2(DataRowView datarow, int addnew, int msv)
        {

        }

        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();

        }

        private void ok_Click_1(object sender, RoutedEventArgs e)
        {
            string masv =masv1.Text;
            string ho = ho1.Text;
            string ten = ten1.Text;
            string ngaysinh = ngsinh.Text;
            string gioitinh= gt.Text;
            string makhoa = makhoa1.Text;


            if (addnew == true)
            {
                hd.LUUHOADON(masv, ho, ten, ngaysinh, gioitinh, makhoa);

            }

            datarow["masv"] = masv;
            datarow["ho"] = ho;
            datarow["ten"] = ten;
            datarow["ngaysinh"] = ngaysinh;
            datarow["gioitinh"] = gioitinh;
            datarow["makhoa"] = makhoa;
            masv1.Text = "";
            ho1.Text = "";
            ten1.Text = "";
            gt.Text = "";
            ngsinh.Text = "";
            masv1.Focus();
            this.Close();
        }
        
        private void them_Click_1(object sender, RoutedEventArgs e)
        {
            DataView dv = (DataView)datagrid.ItemsSource;
            DataRowView row = dv.AddNew();
            row.EndEdit();
            datagrid.Items.Refresh();

        }
        
        private void sua_Click_1(object sender, RoutedEventArgs e)
        {

        }

        private void xoa_Click_1(object sender, RoutedEventArgs e)
        {
            string MSV = datagrid.SelectedValue.ToString();
            MessageBoxResult result = MessageBox.Show(" bạn có muốn xóa sinh viên mã số" + MSV +" không?", "THÔNG BÁO", MessageBoxButton.YesNo, MessageBoxImage.Warning);
            if (result == MessageBoxResult.Yes)
            {
                CA.XOAHOADON(MSV);
                DataRowView rowSelect = (DataRowView)datagrid.SelectedItem;
                rowSelect.Delete();
            }

        }

        private void thoat_Click_1(object sender, RoutedEventArgs e)
        {
            this.Close();

        }

        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            DataTable DT = CA.DANHSACHSINHVIEN();
            datagrid.ItemsSource = DT.DefaultView;
            datagrid.SelectedValuePath = "masv";
        }
        Cau2DAL DAL = new Cau2DAL();
        SINHVIEN CA = new SINHVIEN();
    }
}
